package com.boot.security.server.dao.mffl;

import com.boot.security.server.model.mffl.MfflUser;
import com.boot.security.server.model.mffl.Vo.LawyerUser;
import com.boot.security.server.model.mffl.Vo.LawyerUserVo;
import com.boot.security.server.model.mffl.mfflUserSimple;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface MfflUserDao {

    @Select("select * from  sys_user a,mffl_user t where t.userid = a.id and t.delete_state = 1 and a.phone = #{Phone}")
    MfflUser getByPhone(String Phone);


    //通过父级id找到附属表数据
    @Select("select * from mffl_user t where t.userid = #{id}")
    MfflUser getByUserId(Long id);


    @Select("select * from mffl_user t where t.id = #{id}")
    MfflUser getById(Long id);

    @Delete("delete from mffl_user where id = #{id}")
    int delete(Long id);

    int update(MfflUser mfflUser);

    int updateLawyer(MfflUser mfflUser);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into mffl_user(userid, identity, realname, work_code, area_name, comid, lawfirm, work_boot_image, idnumber, idnumberImage, field, content, education, thirdlevel, server_number, rating, openid, unionid, area_code, register_method, level, start_work_time, integral, grade_integral, search_like, createTime, updateTime, delete_state, deleteTime, money, Secondusername, lawyer_inspect, jpush) values(#{userid}, #{identity}, #{realname}, #{workCode}, #{areaName}, #{comid}, #{lawfirm}, #{workBootImage}, #{idnumber}, #{idnumberImage}, #{field}, #{content}, #{education}, #{thirdlevel}, #{serverNumber}, #{rating}, #{openid}, #{unionid}, #{areaCode}, #{registerMethod}, #{level}, #{startWorkTime}, #{integral}, #{gradeIntegral}, #{searchLike}, #{createTime}, #{updateTime}, #{deleteState}, #{deleteTime}, #{money}, #{Secondusername}, #{lawyerInspect}, #{jpush})")
    int save(MfflUser mfflUser);

    int count(@Param("params") Map<String, Object> params);

    List<MfflUser> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);


    @Select("SELECT * FROM  sys_user su LEFT JOIN mffl_user mu  ON mu.userid = su.id WHERE su.id = #{id}")
    MfflUser getUserInfoAll(@Param("id") Integer id);

    //按照id查找mff_user表
    @Select("SELECT * FROM mffl_user mu LEFT JOIN sys_user su ON mu.userid = su.id WHERE su.id = #{id}")
    MfflUser getmffluser(@Param("id") Integer id);

    @Select("SELECT * FROM sys_user su LEFT JOIN mffl_user mu ON mu.userid = su.id WHERE su.id = #{id}")
    mfflUserSimple getUserInfoSimple(@Param("id") Integer id);

    //查看过审律师是否存在
    @Select("SELECT * FROM sys_user su LEFT JOIN mffl_user mu ON mu.userid = su.id WHERE su.id = #{id} AND identity = 1 AND lawyer_inspect = 1")
    mfflUserSimple getLawyer(@Param("id") Integer id);

    //登录-修改极光推送标识
    @Update("update mffl_user set jpush = #{jpush} where userid = #{userid} ")
    int updateJPush(@Param("jpush") String jpush, @Param("userid") Long id);

    //首页律师
    @Select("SELECT * FROM sys_user su LEFT JOIN mffl_user mu ON mu.userid = su.id WHERE mu.field like concat('%', #{type}, '%') and lawyer_inspect = 1 ORDER BY server_number DESC,rating DESC,start_work_time ASC limit #{count}")
    List<LawyerUser> getUserListByType(@Param("type") Integer type, @Param("count") Integer count);

    @Select("SELECT * FROM sys_user su LEFT JOIN mffl_user mu ON mu.userid = su.id WHERE mu.lawyer_inspect = 1 ORDER BY server_number DESC,rating DESC,start_work_time ASC limit #{count}")
    List<LawyerUser> getUserListByTypeRecommend(@Param("count") Integer count);

    //律师列表
    int getLawyerCount(@Param("params") Map<String, Object> params);

    List<LawyerUser> getLawyerList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //律师详情
    @Select("SELECT * FROM sys_user su LEFT JOIN mffl_user mu ON mu.userid = su.id WHERE su.id = #{id}")
    LawyerUserVo getLawyerUserById(Integer lawyerId);


    //获取律师列表
    int listLaywerCount(@Param("params") Map<String, Object> params);

    List<mfflUserSimple> listLaywer(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //选择律师
    List<LawyerUser> getSelectLawyerList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //律师审核
    int lawyerAuditCount(@Param("params") Map<String, Object> params);

    List<MfflUser> lawyerAuditList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    @Update("update mffl_user set lawyer_inspect = #{lawyerInspect} where id = #{id}")
    int auditLawyer(@Param("id") Long id, @Param("lawyerInspect") Integer type);

    @Update("update mffl_user set rating = #{rating} where userid = #{userid} ")
    void updateRating(@Param("rating") String rating, @Param("userid") Integer userid);


    //普通用户管理
    int userCount(@Param("params") Map<String, Object> params);

    List<MfflUser> userList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    //普通用户管理
    int lawyerCount(@Param("params") Map<String, Object> params);

    List<MfflUser> lawyerList(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    @Select("SELECT mu.*,su.username AS username ,su.nickname AS nickname,su.phone AS phone,su.status AS status FROM  sys_user su LEFT JOIN mffl_user mu  ON mu.userid = su.id WHERE su.id = #{id}")
    MfflUser getUserInfoAllSSL(@Param("id") Integer id);


    //查询openid
    @Select("select * from mffl_user t where t.openid = #{openid} limit 1")
    MfflUser getByoPenid(String openid);

    //按照手机号查询用户
    @Select("SELECT * FROM mffl_user mffl  LEFT JOIN sys_user sys ON mffl.userid = sys.id WHERE sys.phone = #{phone}")
    MfflUser getByPhoneUser(@Param("phone") String phone);

    @Select("select * from mffl_user")
    List<MfflUser> selectMfflUserAllList();

    //提现删除金额
    @Update("update mffl_user set money = #{money},frozenmoney=#{frozenmoney} where userid = #{userid}  ")
    void updateMoney(@Param("money") BigDecimal money, @Param("frozenmoney") BigDecimal frozenmoney, @Param("userid") Integer userid);
}
